package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.Gdtj;
import com.stylefeng.guns.modular.system.service.IGdtjService;
import com.stylefeng.guns.modular.system.warpper.GdtjWarpper;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-05-25 20:40:49
 */
@Controller
@RequestMapping("/gdtj")
public class GdtjController extends BaseController {

    private String PREFIX = "/system/gdtj/";

    @Autowired
    private IGdtjService gdtjService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "gdtj.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/gdtj_add")
    public String gdtjAdd() {
        return PREFIX + "gdtj_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/gdtj_update/{gdtjId}")
    public String gdtjUpdate(@PathVariable Integer gdtjId, Model model) {
        Gdtj gdtj = gdtjService.selectById(gdtjId);
        model.addAttribute("item",gdtj);
        LogObjectHolder.me().set(gdtj);
        return PREFIX + "gdtj_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String name,String dm,String sharestype) {
    	Page<Gdtj> page = new PageFactory<Gdtj>().defaultPage();
    	List<Map<String, Object>> gdhs = gdtjService.selectMapsByDm(page,name,dm,sharestype);
    	page.setRecords((List<Gdtj>) new GdtjWarpper(gdhs).warp());
        return super.packForBT(page);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Gdtj gdtj) {
        gdtjService.insert(gdtj);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer gdtjId) {
        gdtjService.deleteById(gdtjId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Gdtj gdtj) {
        gdtjService.updateById(gdtj);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{gdtjId}")
    @ResponseBody
    public Object detail(@PathVariable("gdtjId") Integer gdtjId) {
        return gdtjService.selectById(gdtjId);
    }
}
